#pragma once

#include <QtWidgets/QWidget>
#include "ui_UnicodeConvert.h"
enum BOM_TYPE
{
	UTF8_NOBOM,
	UTF8_BOM,
	UTF16_BOM_BIG,
	UTF16_BOM_LITTLE,
	UTF32_BOM_BIG ,
	UTF32_BOM_LITTLE,
#ifdef EXTEND_BOM
	UTF7_BOM,
	UTF1_BOM,
	UTF_EBCDIC,
	UTF_SCSU,
	GB18030,
#endif // EXTEND_BOM
};

struct BOM_STR
{
	int head_code;
	int head_len;
	BOM_TYPE type;
	QString name;
};

const BOM_STR g_bom_list[] = {
#ifdef WIN32
			{ 0x00bfbbef, 3, UTF8_BOM, "UTF8_BOM" },
			{ 0x0000fffe, 2, UTF16_BOM_BIG, "UTF16_BOM_BIG" },
			{ 0x0000feff, 2, UTF16_BOM_LITTLE, "UTF16_BOM_LITTLE" },
			{ 0xfffe0000, 4, UTF32_BOM_BIG, "UTF32_BOM_BIG" },
			{ 0x0000feff, 4, UTF32_BOM_LITTLE, "UTF32_BOM_LITTLE" },
#else
		{ 0xefbbbf, 3, UTF8_BOM, "UTF8_BOM" },
		{ 0xfeff, 2, UTF16_BOM_BIG, "UTF16_BOM_BIG" },
		{ 0xfffe, 2, UTF16_BOM_LITTLE, "UTF16_BOM_LITTLE" },
		{ 0x0000feff, 4, UTF32_BOM_BIG, "UTF32_BOM_BIG" },
		{ 0xfffe0000, 4, UTF32_BOM_LITTLE, "UTF32_BOM_LITTLE" },
#endif // WIN32

#ifdef EXTEND_BOM
	{ 0x2B2F76, 4, "UTF7_BOM" },
#endif

	{ 0, 0, UTF8_NOBOM, "UTF8_NOBOM" },			//local last
};
class QStatusBar;
class QLabel;
class UnicodeConvert : public QWidget
{
	Q_OBJECT

public:
	UnicodeConvert(QWidget *parent = Q_NULLPTR);

	void SetCurrentWorkPath(const QString&);
	void DoConvert();

	//void SetTemporaryStatus(const QString&);
	void SetNormalStatus(const QString&);
	void SetPermanentStatus(const QString&);
public slots:
	void SlotStart();
	void SlotChoosePath();
	void SlotSetDstBom();
private:
	void Convert(const QString &);
	const BOM_STR &FindBomByType(BOM_TYPE);
	QString work_path_;
	bool conveted_  = true;

	Ui::UnicodeConvertClass ui;

	BOM_STR dst_bom_;
	qint32 tmp_value_ = 0;
	QStatusBar *status_bar_ = nullptr;
	QLabel *label_normal_bar_ = nullptr;
	QLabel *label_permanent_bar_ = nullptr;
};
